package com.yidu.BusinessData.service.impl;

import com.yidu.BusinessData.entity.Broker;
import com.yidu.BusinessData.mapper.BrokerMapper;
import com.yidu.BusinessData.service.BrokerServce;
import com.yidu.Util.util.Dbutil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * 券商设置实现类
 * @author zhouhongyu
 * @since 2022/8/10
 * @version 1.0
 */
@Service
public class BrokerServceImpl implements BrokerServce {
    @Autowired
    private BrokerMapper brokerMapper;//自动装配
    @Autowired
    private Dbutil dbutil;

    /**
     * 条数
     * @return
     */
    @Override
    public int selectCount() {
        return brokerMapper.selectCount();
    }

    /**
     * 重写条件查询的方法
     * @param brokerName
     * @param page
     * @param limit
     * @return
     */
    @Override
    public List<Broker> selectBroker(String brokerName, int page, int limit) {
        HashMap map = new HashMap();
        map.put("brokerName",brokerName);
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        return brokerMapper.selectBroker(map);
    }

    /**
     * 重写增加数据的方法
     * @param broker
     * @return
     */
    @Override
    public int insertBroker(Broker broker) {
        String maxId = dbutil.getMaxId2("brokerId","broker");
        broker.setBrokerId(maxId);
        return brokerMapper.insertBroker(broker);
    }

    /**
     * 重写删除数据的方法
     * @param brokerId
     * @return
     */
    @Override
    public int  deleteBroker(String brokerId) {
        return brokerMapper.deleteBroker(brokerId);
    }


    /**
     * 重写修改数据的方法
     * @param broker
     * @return
     */
    @Override
    public int updateBroker(Broker broker) {
        return brokerMapper.updateBroker(broker);
    }


}
